package admin.controllers;

import java.io.IOException;
import java.net.URLDecoder;
import java.util.TreeMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import models.UserModel;

import data.UserData;

public class DeleteUserServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {
		TreeMap check = new TreeMap();
		String path = ((HttpServletRequest) request).getRequestURI();
		String username = URLDecoder.decode(path.toLowerCase().replaceAll("/admin/delete-user/", ""),"UTF-8");
		
		UserData userData = new UserData();
		UserModel user = userData.getUser(username);
		
		if (user != null) {
			userData.delete(user);
		}
		
		response.sendRedirect("/admin/list-user");
	}
}
